<template>
  <div class="info">
    <el-form ref="form" :model="ruleForm" label-width="80px">
      <el-form-item label="标题">
        <el-input v-model="ruleForm.title"></el-input>
      </el-form-item>
      <el-form-item label="内容">
        <tinymce v-model="ruleForm.content" :height="400" />
      </el-form-item>
    </el-form>
    <div class="action">
      <el-button type="primary" @click="submitForm">立即保存</el-button>
    </div>
  </div>
</template>

<script>
import Tinymce from "@/components/Tinymce";
import { getInfo, add, update } from "@/api/helpers";

export default {
  name: "helpInfo",
  components: { Tinymce },

  data() {
    return {
      id: this.$route.query.id,
      ruleForm: {
        title: "",
        content: "",
      },
    };
  },
  mounted() {
    this.getInfo();
  },
  methods: {
    async getInfo() {
      const res = await getInfo({ id: this.id });
      if (res.data) {
        this.ruleForm = res.data;
      }
    },
    async submitForm() {
      const postData = Object.assign({}, this.ruleForm);
      const func = this.id ? update : add;
      const res = await func(postData);
      if (res) {
        this.$router.go(-1);
      }
    },
  },
};
</script>
<style lang="scss" scoped>
.action {
  margin-top: 20px;
  display: flex;
  justify-content: center;
}
</style>